package com.zs.java.blockingqueue;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/**
 * @author madison
 * @description
 * @date 2021/6/2 10:40
 */
public class LinkedBlockingDequeTest {


    public static void main(String[] args) {
        LinkedBlockingDeque deque = new LinkedBlockingDeque(3);

        new Thread(() -> {
            try {
                while (true){
                    System.out.println("等待获取数据......");
                    TimeUnit.SECONDS.sleep(2);
                    System.out.println("还没数据,继续等待...");
                    System.out.println("获取到数据:" + deque.takeFirst());
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(() -> {
            try {
                while (true){
                    System.out.println("等以后存储数据...");
                    TimeUnit.SECONDS.sleep(6);
                    System.out.println("马上存储数据...");
                    deque.addFirst(7);
                    deque.addFirst(2);
                    deque.addFirst(9);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
